//
//  Reward:ViewController.m
//  ZiJinLian
//
//  Created by 🐛 on 2017/4/14.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "RewardViewController.h"
#import "WallCollectionHeadView.h"
#import "WarkCollectionViewCell.h"
#import "WarkCollectionHeadView.h"

@interface RewardViewController ()<UICollectionViewDelegate,
UICollectionViewDataSource,WarkCollectionHeadViewDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic,assign) NSInteger num;
@end

@implementation RewardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.collectionView];
    self.num=0;
}
- (UICollectionView *)collectionView
{
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc] init];
        //设置滚动方向
        [flowlayout setScrollDirection:UICollectionViewScrollDirectionVertical];
        //左右间距
        flowlayout.minimumInteritemSpacing =5;
        //上下间距
        flowlayout.minimumLineSpacing =5 ;
        [flowlayout setHeaderReferenceSize:CGSizeMake(MainW,270+MainW/3)];
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, MainW, MainH-64) collectionViewLayout:flowlayout];
        _collectionView.backgroundColor = Gray_Color;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        
        [_collectionView registerNib:[UINib nibWithNibName:@"WarkCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"ShopsCell"];
        [_collectionView registerClass:[WarkCollectionHeadView class]
            forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
                   withReuseIdentifier:@"WarkCollectionHeadView"];
        //_collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreTopic)];
        
    }
    return _collectionView;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.num;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    WarkCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ShopsCell" forIndexPath:indexPath];
    
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((MainW-15)/2, (MainW-15)*3/4+15);
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10, 5, 5, 5);//分别为上、左、下、右
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
           viewForSupplementaryElementOfKind:(NSString *)kind
                                 atIndexPath:(NSIndexPath *)indexPath
{
    NSString *reuseIdentifier;
    if ([kind isEqualToString:UICollectionElementKindSectionHeader])
    { // header
        reuseIdentifier = @"WarkCollectionHeadView";
    }
    WarkCollectionHeadView *view = [collectionView dequeueReusableSupplementaryViewOfKind:kind
                                                                      withReuseIdentifier:reuseIdentifier
                                                                             forIndexPath:indexPath];
    view.delgeate=self;
    if ([kind isEqualToString:UICollectionElementKindSectionHeader])
    {
        // CollectionCategoryModel *model = self.dataSource[indexPath.section];
        
        //NSLog(@"名称:%@",model.name);
    }
    return view;
}
-(void)chooseClassesClick:(UIButton *)sender Choose:(NSMutableDictionary *)dic{
    NSInteger a=2*dic.count;
    self.num=a;
    [self.collectionView reloadData];
    NSLog(@"没有执行");
}
-(void)submitClick:(NSMutableDictionary *)dic NSString:(NSString *)text{
    NSLog(@"类型  :%@  输入框内容:%@",dic,text);
}


@end
